package com.transaction.simulate.controller;

import com.transaction.common.base.BaseController;
import com.transaction.common.util.ParamsUtil;
import com.transaction.simulate.model.dto.Channel;
import com.transaction.simulate.model.vo.ChannelAccountVo;
import com.transaction.simulate.service.ChannelService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/channel")
public class ChannelController extends BaseController {

    private static Logger LOGGER = LoggerFactory.getLogger(ChannelController.class);

    @Autowired
    private ChannelService channelService;

    /**
     * 查询渠道信息
     * @Title: getChannel
     * @author: dy.yin 2021/8/24 16:02
     */
    @GetMapping("/getChannel")
    public Object getChannel(HttpServletRequest request){
        Channel channel = ParamsUtil.getBeanParam(new Channel(),request);
        return channelService.getChannel(channel);
    }

    //删除渠道
    @PostMapping("/deleteChannel")
    public Object deleteChannel(@RequestBody ChannelAccountVo channelAccountVo){
        List<Channel> channelList = channelAccountVo.getChannels();
        return channelService.deleteChannel(channelList);
    }

    //新增渠道
    @PostMapping("/addChannel")
    public Object addChannel(@RequestBody Channel channel){
        channelService.addChannel(channel);
        return retResultVo();
    }
}
